home *** CD-ROM | disk | FTP | other *** search
- // Copyright 1998 Macromedia, Inc. All rights reserved.
- //******************* GLOBALS **********************
-
- function initGlobals() {
- ACTION_PLAY = "play";
- ACTION_STOP = "stop";
- }
-
- var ACTION_PLAY;
- var ACTION_STOP;
-
-
- //******************* BEHAVIOR FUNCTION **********************
-
- //Plays a soundfile, or stops one from playing.
- //Accepts the following arguments:
- // sndAction - currently, 'stop' or 'play'
- // sndObj - Javascript object reference for sound EMBED (ex: document.mySound)
- //
- //Tests if the object exists, then initiates the action on the object.
- //For stop, the stop() method is called. For play(), the play() method
- //is called for Netscape; for IE, either play() or run() is called depending
- //on the plugin: the new Windows Media Player uses the new Netshow 2 API and
- //consequently requires play(). The old plugin uses the DirectShow API and
- //requires the run() method after ensuring that the FileName property is
- //assigned.
-
- function MM_controlSound(sndAction,_sndObj) { //v2.0
- var sndObj = eval( _sndObj );
- if (sndObj != null) {
- if (sndAction=='stop') {
- sndObj.stop();
- } else {
- if (navigator.appName == 'Netscape' ) {
- sndObj.play();
- } else {
- if (document.MM_WMP_DETECTED == null) {
- document.MM_WMP_DETECTED = false;
- var i;
- for( i in sndObj )
- if ( i == "ActiveMovie" ) {
- document.MM_WMP_DETECTED = true;
- break; }
- }
- if (document.MM_WMP_DETECTED)
- sndObj.play();
- else if ( sndObj.FileName )
- sndObj.run();
- }}}}
-
- //******************* API **********************
-
-
- //Can be used with any tag and any event
-
- function canAcceptBehavior(){
- return true;
- }
-
-
-
- //Returns a Javascript function to be inserted in HTML head with script tags.
-
- function behaviorFunction(){
- return "MM_controlSound";
- }
-
-
-
- //Returns fn call to insert in HTML tag <TAG... onEvent='thisFn(arg)'>
-
- function applyBehavior() {
- var i, sndAction, menuIndex, sndFile="", sndName="";
-
- //Based on action (Play or Stop) get the sound filename from the INPUT or SELECT
- sndAction = (document.theForm.theRadio[0].checked)?ACTION_PLAY:ACTION_STOP;
- if (sndAction == ACTION_PLAY) {
- sndFile = document.theForm.sndFileObj.value; //if play, get filename from text input
- } else { //ACTION_STOP
- menuIndex = document.theForm.menu.selectedIndex; //get index selected
- if (menuIndex != -1 && document.theForm.menu.options[menuIndex].text.indexOf("***")!=0)
- sndFile = document.theForm.menu.options[menuIndex].text; //if stop get from menu
- }
-
- //If snd EMBED already exists, we want to return the old sndName
- for (i=0; i<document.theForm.menu.options.length; i++) { //scan menu for name
- if (document.theForm.menu.options[i].text == sndFile) { //if already existing
- sndName = document.MM_sndNames[i]; break;//get prior uniquename
- } }
-
- if (!sndName || document.NEW_SOUND) { //sound didn't exist, create it
- if (!sndName) sndName = "CS"+((new Date()).getTime()); //create unique name
- createSoundObject(sndName,sndFile);
- }
-
- //return function call or error message
- if (sndFile) return "MM_controlSound('"+sndAction+"','document."+sndName+"','"+sndFile+"')";
- else return MSG_NoSndFile;
- }
-
-
-
- //Passed the function call above, takes prior arguments and reloads the UI.
-
- function inspectBehavior(fnCallStr) {
- var i, sndAction, sndName, menuLength;
- var tempArray, argArray = new Array;
-
- //get previous args
- argArray = extractArgs(fnCallStr);
- if (argArray.length == 4) {
- sndAction = argArray[1];
- sndName = dreamweaver.getTokens(argArray[2],".")[1]; //remove "document.", use unique name
- sndFile = argArray[3];
-
- with (document.theForm) {
- theRadio[sndAction==ACTION_PLAY?0:1].checked = true; //select radio
- //try and locate the sound object name in the list of known sound objects
- for (i=0; i<document.MM_sndNames.length && document.MM_sndNames[i]!=sndName; i++);
- if (i < document.MM_sndNames.length) { //snd found, select it
- if (sndAction == ACTION_PLAY) sndFileObj.value = menu.options[i].text; //PLAY: show name
- else menu.selectedIndex = i; //STOP: select sound
- } else {
- if (sndAction == ACTION_PLAY) sndFileObj.value = sndFile; //PLAY: show name
- else { //didn't exists, but add to menu and applyBehavior will create it
- menuLength = document.MM_sndNames.length;
- document.MM_sndNames[menuLength] = sndName; //add to list
- menu.options[menuLength]= new Option(sndFile); //add to menu
- menu.selectedIndex = Math.max(0,menuLength - 1); //select new menu item
- document.NEW_SOUND = true;
- } } } }
- }
-
-
-
- //Given the original function call, this parses out the args and maybe
- //removes associated sound embed calls. Only if:
- //1) there's an embed with the same name
- //2) when scanning the entire doc, name only found once
-
- function deleteBehavior(fnCallStr) {
- var argArray,sndName,doc,tagArray,i,embedName;
-
- argArray = extractArgs(fnCallStr);
- if (argArray.length > 2) {
- sndName = dreamweaver.getTokens(argArray[2],".")[1]; //remove "document.", use unique name
- //Find all EMBED calls that we created (name starts with "CS"), add to menu
- doc = dreamweaver.getDocumentDOM("document"); //get all
- tagArray = doc.getElementsByTagName("EMBED");
- for (i=0; i<tagArray.length; i++) { //with each EMBED tag
- embedName = tagArray[i].name;
- if (embedName == sndName) { //if same embed
- if ( -1 == doc.body.outerHTML.indexOf( argArray[2] ) ) // and embed ref'd no where else
- tagArray[i].outerHTML = "";
- break;
- } } }
- }
-
-
-
- //***************** LOCAL FUNCTIONS ******************
-
-
- //Finds any previous sound EMBEDs and adds them to the Stop Sound menu.
-
- function initializeUI() {
- initGlobals();
- var i,j,tagArray,embedName,embedSrc;
- document.MM_sndNames = new Array;
-
- //Find all EMBED calls that we created (name starts with "CS"), add to menu
- tagArray = dreamweaver.getDocumentDOM("document").getElementsByTagName("EMBED");
- for (i=0; i<tagArray.length; i++) { //with each EMBED tag
- embedName = tagArray[i].name;
- embedSrc = unescape(tagArray[i].src);
- if (embedName && embedName.indexOf("CS") == 0 && embedSrc) with (document) { //if one of ours
- for (j=0; j<MM_sndNames.length && embedSrc != theForm.menu.options[j].text; j++); //search
- if (j == MM_sndNames.length) { //if not there
- MM_sndNames[j] = embedName; //save sound name for later
- theForm.menu.options[j]= new Option(embedSrc); //add to menu
- } } }
-
- document.theForm.sndFileObj.focus(); //set focus on textbox
- document.theForm.sndFileObj.select(); //set insertion point into textbox
- }
-
-
-
- //Creates a sound embed object, given a name and file. This object is appended to the
- //end of the user's document (the end of the BODY tag).
-
- function createSoundObject(sndName,sndFile) {
- var objStr;
- objStr = "<EMBED NAME=\'"+sndName+"\' SRC=\'"+escape(sndFile)+"\' LOOP=false \n"+
- "AUTOSTART=false MASTERSOUND HIDDEN=true WIDTH=0 HEIGHT=0></EMBED>\n";
- bodyObj = dreamweaver.getDocumentDOM("document").body; //get body
- bodyObj.innerHTML = bodyObj.innerHTML + objStr; //append new embed
- }
-
-
-
- //**************** GENERIC FUNCTIONS ****************
-
- //function browseFile(fieldToStoreURL){
-